package com.example.androidcomplete0102.ch13;

import com.example.androidcomplete0102.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;

public class TimePickerTest extends Activity {
	TimePicker mTime;
	TextView mTxtTime;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch13_timepickertest);
		mTime =(TimePicker)findViewById(R.id.timepicker);
		mTxtTime =(TextView)findViewById(R.id.txttime);
		mTime.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
			
			@Override
			public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
				mTxtTime.setText(String.format("%d:%d", hourOfDay, minute));
			}
		});
		
		findViewById(R.id.btntoggle24).setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				mTime.setIs24HourView(!mTime.is24HourView());
			}
		});
		
		findViewById(R.id.btnnow2).setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				String result = String.format("%d시%분",mTime.getCurrentHour(),
						mTime.getCurrentMinute());
				Toast.makeText(TimePickerTest.this, result, 0).show();
			}
		});
	}
}
